/**
 * Project Name:javaBaseReview
 * Package Name:com.xuwei.base.tree
 * author:David
 * Date:2015年6月18日下午7:34:28
 * Copyright (c) 2015, xw123box@126.com All Rights Reserved.
 *
 */
package com.xuwei.base.tree;

/**
 * 赫夫曼树结点定义
 * @author David
 * @since 2015年6月18日 下午7:34:28
 * @version
 * @since JDK 1.6
 */
public class HuffmanTreeNode {
	private int weight;// 权值
	private String coding = "";// 编码
	private HuffmanTreeNode parent;//父节点
	private HuffmanTreeNode lchild;//左子树(结点)
	private HuffmanTreeNode rchild;//右子树(结点)
	private boolean isleft; //是否是左子树（结点）

	public boolean isIsleft() {
		return isleft;
	}

	public void setIsleft(boolean isleft) {
		this.isleft = isleft;
	}

	// 构造方法
	public HuffmanTreeNode(int weight) {
		this.weight = weight;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public String getCoding() {
		return coding;
	}

	public void setCoding(String coding) {
		this.coding = coding;
	}

	public HuffmanTreeNode getLchild() {
		return lchild;
	}

	public void setLchild(HuffmanTreeNode lchild) {
		this.lchild = lchild;
	}

	public HuffmanTreeNode getRchild() {
		return rchild;
	}

	public void setRchild(HuffmanTreeNode rchild) {
		this.rchild = rchild;
	}

	public HuffmanTreeNode getParent() {
		return parent;
	}

	public void setParent(HuffmanTreeNode parent) {
		this.parent = parent;
	}

	/**
	 * 判断当前结点是否有父节点
	 * @return
	 */
	public boolean hasParent() {
		if(this.getParent()!=null){
			return true;
		}
		return false;
	}

	/**
	 * 判断当前结点是否是左子树
	 * @return
	 */
	public boolean isLChild() {
		if(isleft){
			return true;
		}
		return false;
	}
	
	/**
	 * 判断当前结点是否是父节点
	 * @return
	 */
	public boolean hasChild(){
		if(this.getLchild()!=null||this.getRchild()!=null){
			return true;
		}
		return false;
	}
	
}
